# Maintainer: Hoang Nguyen <folliekazetani@protonmail.com>
pkgname=rootlesskit
pkgver=1.1.1
pkgrel=0
pkgdesc="Linux-native fake root for implementing rootless containers"
url="https://github.com/rootless-containers/rootlesskit"
arch="all"
license="Apache-2.0"
depends="shadow-subids iproute2-minimal"
makedepends="go"
subpackages="
	$pkgname-docker-proxy:_docker_proxy
	$pkgname-doc
	"
source="$pkgname-$pkgver.tar.gz::https://github.com/rootless-containers/rootlesskit/archive/refs/tags/v$pkgver.tar.gz"
options="net" # fetch dependencies

export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

build() {
	mkdir -v build
	go build -v \
		-ldflags "-X github.com/rooless-containers/rootlesskit/pkg/version.Version=$pkgver" \
		-o build ./cmd/...
}

check() {
	# fork/exec /proc/self/exe: operation not permitted
	# shellcheck disable=2046
	go test $(go list ./... | grep -v pkg/port/builtin)
}

package() {
	install -Dm755 build/rootlesskit -t "$pkgdir"/usr/bin
	install -Dm755 build/rootlessctl -t "$pkgdir"/usr/bin
	install -Dm644 docs/*.md -t "$pkgdir"/usr/share/doc/$pkgname
}

_docker_proxy() {
	pkgdesc="$pkgdesc - Docker proxy"
	install_if="$pkgname=$pkgver-r$pkgrel docker-engine"
	install -Dm755 "$builddir"/build/rootlesskit-docker-proxy -t "$subpkgdir"/usr/bin
}

sha512sums="
2ce4409af0c5d4a44db1c1e35bbbe2f74dc2bc8d2161839600b57ef811cd1ebeb2db24e1c93bbba63995e4205e6937b64179bc58c7407894bb5dc737a2ce535e  rootlesskit-1.1.1.tar.gz
"
